package pe.com.rimac.portal.common.interceptor;

import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.portlet.handler.HandlerInterceptorAdapter;

import pe.com.rimac.portal.common.holder.RequestHolder;

public class RequestInterceptor extends HandlerInterceptorAdapter
{
	private static final Logger logger = Logger.getLogger(RequestInterceptor.class);
	
	@Override
	protected boolean preHandle(PortletRequest portletRequest, PortletResponse portletResponse, Object handler) throws Exception 
	{
        logger.debug("Storing Portlet request for session id '" + portletRequest.getRequestedSessionId()
                + "' to thread");
        RequestHolder.setPortletRequest(portletRequest);
		return true;
	}
	
	@Override
	protected void afterCompletion(PortletRequest portletRequest, PortletResponse portletResponse, Object handler, Exception ex) throws Exception 
	{
        logger.debug("Removing Portlet request for session id '" + portletRequest.getRequestedSessionId()
                + "' from thread");
        RequestHolder.setPortletRequest(null);
	}
}